package com.example.entity;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import java.io.Serializable;
import java.time.LocalDateTime;

import com.example.util.DateUtil;
import lombok.Getter;
import lombok.Setter;

/**
 * @author iKun
 * @since 2024-06-17
 */
@Getter
@Setter
public class Book implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    /**
     * 书名
     */
    private String bookName;

    /**
     * 简介
     */
    private String description;

    /**
     * 作者
     */
    private String author;

    /**
     * 数量(本)
     */
    private Integer number;

    /**
     * 单价(元)
     */
    private Double price;

    /**
     * 发布时间
     */
    private LocalDateTime published;

    /**
     * 用于页面显示的时间字符串，符合国人习惯
     * 不参与数据库表操作
     */
    @TableField(exist = false)
    private String publishedDate;

    /**
     * 是否有效
     */
    private Integer isActive;

    /**
     * 覆盖lombok提供的setPublished方法
     * @param published
     */
    public void setPublished(LocalDateTime published) {
        this.published = published;
        setPublishedDate(DateUtil.toTimeStr(published));
    }
}